import type { TableColumn } from '@/components/core/dynamic-table';

export type TableListItem = API.StrativeListPageResultItem;
export type TableColumnItem = TableColumn<TableListItem>;

let taskStatusList = [
  {
    label: '全部',
    value: 0,
  },
  {
    label: '未开始',
    value: 1,
  },
  {
    label: '进行中',
    value: 2,
  },
  {
    label: '待审批',
    value: 3,
  },
  // {
  //   label: '技术复核',
  //   value: 4,
  // },
  {
    label: '文书制作',
    value: 5,
  },
  {
    label: '送达回证',
    value: 6,
  },
  {
    label: '已结束',
    value: 7,
  },
];

const caseTaskStatus = (val) => {
  switch (val) {
    case 1:
      return '未开始';
    case 2:
      return '进行中';
    case 3:
      return '待审批';
    // case 4:
    //   return '技术复核';
    case 5:
      return '文书制作';
    case 6:
      return '送达回证';
    case 7:
      return '已结束';
    default:
      break;
  }
};

const caseTextColor = (val) => {
  switch (val) {
    case 1:
      return 'color: #999999';
    case 2:
      return 'color: #1677FF';
    case 3:
      return 'color: #F5820F';
    // case 4:
    //   return '技术复核';
    case 5:
      return 'color: #363687';
    case 6:
      return 'color: #10A0AD';
    case 7:
      return 'color: #09B840';
    default:
      break;
  }
};

const checkName = (checkerName, organizerName) => {
  if (checkerName && organizerName) {
    return checkerName + '，' + organizerName;
  } else if (checkerName == '') {
    return organizerName;
  } else if (organizerName == '') {
    return checkerName;
  }
};

let checkResultList = [
  {
    label: '全部',
    value: 0,
  },
  {
    label: '合格',
    value: 1,
  },
  {
    label: '不合格',
    value: 2,
  },
];
const caseCheckResult = (val) => {
  switch (val) {
    case 1:
      return '合格';
    case 2:
      return '不合格';
    default:
      return '-';
  }
};

export const baseColumns: TableColumnItem[] = [
  {
    title: '关键词',
    dataIndex: 'keyword',
    hideInTable: true,
    searchField: 'keyword',
    formItemProps: {
      labelWidth: 55,
      componentProps: () => {
        return {
          placeholder: '可输入任务编号、场所名称搜索',
          autocomplete: 'off',
          disabledLabelWidth: true,
        };
      },
    },
  },
  {
    title: '任务编号',
    width: 120,
    dataIndex: 'taskNo',
    hideInSearch: true,
  },
  {
    title: '场所名称',
    width: 120,
    dataIndex: 'placeName',
    hideInSearch: true,
  },
  {
    title: '任务状态',
    width: 40,
    dataIndex: 'taskStatus',
    resizable: true,
    formItemProps: {
      component: 'Select',
      componentProps: () => ({
        options: taskStatusList,
      }),
      defaultValue: 0,
    },
    customRender: ({ record }) => (
      <div style={caseTextColor(record.taskStatus)}>{caseTaskStatus(record.taskStatus)}</div>
    ),
  },
  {
    title: '结果判定',
    width: 40,
    dataIndex: 'checkResult',
    resizable: true,
    formItemProps: {
      component: 'Select',
      componentProps: () => ({
        options: checkResultList,
      }),
      defaultValue: 0,
    },
    customRender: ({ record }) => caseCheckResult(record.checkResult),
  },
  {
    title: '检查人',
    dataIndex: 'checkerName',
    width: 120,
    hideInSearch: true,
    customRender: ({ record }) => checkName(record.checkerName, record.organizerName),
  },
  {
    title: '检查时间',
    dataIndex: 'endCheckTime',
    width: 60,
    hideInSearch: true,
  },
];
